package com.company.myfirstjmixproject.entity.bom;

import com.company.myfirstjmixproject.entity.enums.ProdTypeEnum;
import io.jmix.core.entity.annotation.JmixGeneratedValue;
import io.jmix.core.metamodel.annotation.JmixEntity;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDateTime;

@JmixEntity
@Table(name = "MST_BOM_PRODUCT", uniqueConstraints = {
        @UniqueConstraint(name = "IDX_MST_BOM_PRODUCT_UNQ", columnNames = {"ITEM_CODE"})
})
@Entity
public class BomProduct {

    @JmixGeneratedValue
    @Column(name = "ID", nullable = false)
    @Id
    private Long id;

    @Column(name = "VERSION", nullable = false)
    @Version
    private Integer version;

    @NotNull
    @JoinColumn(name = "BOM_ID", nullable = false)
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private BomHeader bomHeader;

    @NotNull
    @JoinColumn(name = "ITEM_CODE", nullable = false)
    @OneToOne(fetch = FetchType.LAZY, optional = false)
    private Item item;

    /**
     * 产成品单位
     */
    @Column(name = "ITEM_UOM", nullable = false)
    private String itemUom;

    /**
     * 产成品数量
     */
    @Column(name = "ITEM_QTY", nullable = false)
    private BigDecimal itemQty;

    /**
     * 产成品类型
     */
    @Column(name = "PROD_TYPE", nullable = false)
    private String prodType;

    /**
     * 产出比率
     */
    @Column(name = "PROD_RATIO", nullable = false)
    private BigDecimal prodRatio;

    /**
     * 创建人
     */
    @Column(name = "CREATE_BY")
    private String createBy;

    /**
     * 创建时间
     */
    @Column(name = "CREATE_TIME")
    private LocalDateTime createTime;

    /**
     * 上次修改人
     */
    @Column(name = "LAST_MODIFIED_BY")
    private String lastModifiedBy;

    /**
     * 上次修改时间
     */
    @Column(name = "LAST_MODIFIED_TIME")
    private LocalDateTime lastModifiedTime;

    public String getCreateBy() {
        return createBy;
    }

    public void setCreateBy(String createBy) {
        this.createBy = createBy;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public String getLastModifiedBy() {
        return lastModifiedBy;
    }

    public void setLastModifiedBy(String lastModifiedBy) {
        this.lastModifiedBy = lastModifiedBy;
    }

    public LocalDateTime getLastModifiedTime() {
        return lastModifiedTime;
    }

    public void setLastModifiedTime(LocalDateTime lastModifiedTime) {
        this.lastModifiedTime = lastModifiedTime;
    }

    public BigDecimal getProdRatio() {
        return prodRatio;
    }

    public void setProdRatio(BigDecimal prodRatio) {
        this.prodRatio = prodRatio;
    }

    public void setProdType(String prodType) {
        this.prodType = prodType;
    }

    public ProdTypeEnum getProdType() {
        return prodType == null ? null : ProdTypeEnum.fromId(prodType);
    }

    public void setProdType(ProdTypeEnum prodType) {
        this.prodType = prodType == null ? null : prodType.getId();
    }

    public String getItemUom() {
        return itemUom;
    }

    public void setItemUom(String itemUom) {
        this.itemUom = itemUom;
    }

    public BigDecimal getItemQty() {
        return itemQty;
    }

    public void setItemQty(BigDecimal itemQty) {
        this.itemQty = itemQty;
    }

    public void setBomHeader(BomHeader bomHeader) {
        this.bomHeader = bomHeader;
    }

    public BomHeader getBomHeader() {
        return bomHeader;
    }

    public void setItem(Item item) {
        this.item = item;
    }

    public Item getItem() {
        return item;
    }

    public Integer getVersion() {
        return version;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }
}